import cv2


class CameraClass:

    def __init__(self, horizontal_resolution, vertical_resolution, camera_usb_index):
        self.camera = None
        self.horizontal_resolution = horizontal_resolution
        self.vertical_resolution = vertical_resolution
        self.camera_usb_index = camera_usb_index

    def camera_init(self):
        self.camera = cv2.VideoCapture(0, cv2.CAP_DSHOW)
        self.camera.set(cv2.CAP_PROP_FRAME_WIDTH, self.horizontal_resolution)
        self.camera.set(cv2.CAP_PROP_FRAME_HEIGHT, self.vertical_resolution)

    def camera_datas_capture(self):
        ret, frame = self.camera.read()
        if ret:
            frame = cv2.flip(frame, 1)
            return frame
        return None

    def camera_exit(self):
        if self.camera:
            self.camera.release()

    def bgr_to_rgb(self, frame):
        return cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

    def bgr_to_gray(self, frame):
        return cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
